#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};

ListNode* reverseKGroup(ListNode* head, int k) {
    ListNode* cur = head;
    int n = 0;

    while (cur != nullptr)
    {
        cur = cur->next;
        n++;
    }
    n /= k;


    ListNode* newList = new ListNode(0);
    ListNode* tail = newList;
    cur = head;

    for (int i = 0; i < n; ++i)
    {
        ListNode* tmp = cur;
        for (int j = 0; j < k; ++j)
        {
            ListNode* next = cur->next;

            cur->next = tail->next;
            tail->next = cur;
            cur = next;
        }
        tail = tmp;
    }

    tail->next = cur;
    cur = newList->next;

    return cur;

}

int main() 
{

	return 0;
}